#include"HeapGreater.hpp"
#include<functional>
void test_HeapGreater0()
{
	HeapGreater<int, less<int>> hp;
	hp.push(0);
	hp.push(4);
	hp.push(3);
	hp.push(2);
	hp.push(6);
	hp.push(1);
	while (!hp.empty())
	{
		cout << hp.top() << endl;
		hp.pop();
	}
}
void test_HeapGreater1()
{
	HeapGreater<string, greater<string>> heap;
	heap.push("a");
	heap.push("c");
	heap.push("b");
	heap.push("d");
	heap.push("e");
	heap.push("z");
	heap.push("x");

	heap.erase("e");
	heap.set("c", "new c");
	while (!heap.empty())
	{
		cout << heap.top() << endl;
		heap.pop();
	}
}
struct cmp
{
	//比较的对象是string*类型对象
	bool operator()(string*& l, string*& r)
	{
		return *l < *r;//比较string对象,根据ascii比较
	}
};
void test_HeapGreater2()
{
	string* s1 = new string("a");
	string* s2 = new string("c");
	string* s3 = new string("b");
	string* s4 = new string("d");
	string* s5 = new string("e");
	string* s6 = new string("e");
	string* s7 = new string("z");
	string* s8 = new string("new c");

	HeapGreater<string*, cmp> heap;
	heap.push(s1);
	heap.push(s2);
	heap.push(s3);
	heap.push(s4);
	heap.push(s5);
	heap.push(s6);
	heap.push(s7);

	heap.erase(s5);
	heap.set(s2, s8);
	while (!heap.empty())
	{
		cout << *heap.top() << endl;
		heap.pop();
	}
}
void test_HeapGreater3()
{
	vector<string>v = { "a" ,"c" ,"b" ,"d" ,"e" ,"x" ,"z" };
	HeapGreater<string, less<string>> heap(v.begin(), v.end());

	heap.erase("e");
	heap.set("c", "new c");
	while (!heap.empty())
	{

		cout << heap.top() << endl;
		heap.pop();
	}
}
int main()
{
	test_HeapGreater3();
	return 0;
}